package com.mdd.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.mdd.admin.service.ICompetitionRuleService;
import com.mdd.admin.validate.competition.CompetitionRuleCreateValidate;
import com.mdd.common.entity.competition.CompetitionRule;
import com.mdd.common.mapper.competition.CompetitionRuleMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CompetitionRuleServiceImpl implements ICompetitionRuleService {

    @Autowired
    private CompetitionRuleMapper competitionRuleMapper;

    @Override
    public CompetitionRule detail(Integer id,Integer competitionId,Integer schedule) {

        return competitionRuleMapper.selectOne(new LambdaUpdateWrapper<CompetitionRule>()
                .eq(CompetitionRule::getCompetitionId,competitionId)
                .eq(CompetitionRule::getSchedule,schedule));
    }

    @Override
    public void add(CompetitionRuleCreateValidate createValidate) {
        CompetitionRule rule = new CompetitionRule();
        BeanUtils.copyProperties(createValidate,rule);
        competitionRuleMapper.insert(rule);
    }

    @Override
    public void edit(CompetitionRuleCreateValidate updateValidate) {
        CompetitionRule rule = new CompetitionRule();
        BeanUtils.copyProperties(updateValidate,rule);
        competitionRuleMapper.updateById(rule);
    }
}
